<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require_once(APPPATH . 'models/model_grup.php');

class Grup extends CI_Controller {

	public function __construct()
	{
		parent::__construct();
	}

	# ========== LIHAT GRUP =========

	public function index()
	{
		$this->load->library('table');

		$data['grup_array'] = model_grup::read();

		$this->load->view('theme/theme_kepala');
		$this->load->view('grup/grup_lihat', $data);
		$this->load->view('theme/theme_kaki');
	}

	# ========== TAMBAH GRUP =========

	public function tambah()
	{
		$data = array(
					'judul' => 'Tambah Grup',
					'url'=>'/grup/tambah_proses',
					'isi_form'=>array(
									'grup_id'	=>"",
									'nama'		=>"",
									'keterangan'=>"",
								),
				);

		$this->load->view('theme/theme_kepala');
		$this->load->view('grup/grup_formulir', $data);
		$this->load->view('theme/theme_kaki');
	}

	public function tambah_proses()
	{
		model_grup::create($this->input->post());

		redirect(site_url('/grup'), 'refresh');
	}

	# ========== UBAH GRUP =========

	public function ubah($id="")
	{
		if ($id=="") show_404();

		$form_isi = model_grup::read(array('grup_id'=>$id))[$id];

		// jika kontak tidak ditemukan
		if ($form_isi===false) show_404();

		$data = array(
			'url'=>'/grup/ubah_proses',
			'judul' => 'Ubah Grup',
			'isi_form'=>array(
							'grup_id'	=>$form_isi->get_id(),
							'nama'		=>$form_isi->get_nama(),
							'keterangan'=>$form_isi->get_keterangan(),
						),
		);

		$this->load->view('theme/theme_kepala');
		$this->load->view('grup/grup_formulir', $data);
		$this->load->view('theme/theme_kaki');		
	}


	public function ubah_proses()
	{
		$data = $this->input->post();

		// update kontak
		model_grup::update(array('grup_id'=>$data['grup_id']),$data);

		redirect(site_url('/grup'), 'refresh');
	}

	# ========== HAPUS GRUP =========

	public function hapus($id="")
	{
		if ($id=="") show_404();

		model_grup::delete(array('grup_id'=>$id));

		model_crud::$tabel="pbk_relasi";
		model_crud::$tabel_join=array();
		model_crud::delete(array('grup_id'=>$id));

		redirect(site_url('/grup'), 'refresh');
	}
}

/* End of file utama.php */
/* Location: ./application/controllers/utama.php */